package com.jy.oms.framework.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;

import java.text.MessageFormat;

public class WxRobotUtils {
    public static String robotWebhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={0}";

    public static String sendMsg(String key, String msg) {
        JSONObject text = new JSONObject().fluentPut("content", msg);
        String msgJson = new JSONObject().fluentPut("msgtype", "text").fluentPut("text", text).toJSONString();
        String robotUrl = MessageFormat.format(robotWebhook, key);
        String result = HttpUtil.post(robotUrl, msgJson, 5000);
        return result;
    }

    public static String sendMarkdownMsg(String key, String msg) {
        JSONObject text = new JSONObject().fluentPut("content", msg);
        String msgJson = new JSONObject().fluentPut("msgtype", "markdown").fluentPut("markdown", text).toJSONString();
        String robotUrl = MessageFormat.format(robotWebhook, key);
        String result = HttpUtil.post(robotUrl, msgJson, 5000);
        return result;
    }
}
